/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package carrello.impl.boundary.administrator;

import carrello.impl.boundary.AbstractUI;
import carrello.impl.controller.administrator.ManageUsersCTRL;
import carrello.model.entities.User;
import java.util.List;

/**
 *
 * @author Usman
 */
public class ManageUsersUI extends AbstractUI{
    // list all the private fields 
    private List<User> users;
    private String[] values;
    public List<User> getusers () {
        return users;
    }
    public void setusers (List<User> u ) {
        users = u;
    }
    public void setvalues (String[] v ) {
        values = v;
    }

    @Override
    public String execute () {
        if ( !getSessionIsLoggedIn())
            return ERROR;

        users = ManageUsersCTRL.getAllUsers ();
        if ( values != null ) {
            if ( ManageUsersCTRL.updateUserPrivileges( users, values )) {
                User u = ManageUsersCTRL.getUserPrivileges ( getSessionUsername());
                if ( u != null ) {
                    if ( u.getRole().compareTo("Admin") != 0 )
                        setSessionRole(u.getRole());
                }
                return SUCCESS;
            }
        }
        return INPUT;
    }
}
